package com.hzy.fivepalace.admin.controller;

import com.hzy.fivepalace.admin.annotation.Login;
import com.hzy.fivepalace.admin.controller.base.BaseController;
import com.hzy.fivepalace.admin.dao.AdminLoginInfo;
import com.hzy.fivepalace.admin.service.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/admin/auth")
@Validated
@Api(tags = "鉴权服务")
public class AdminAuthController extends BaseController {

    private static final Logger logger = LoggerFactory.getLogger(AdminAuthController.class);

    @Resource
    private LoginService loginService;


    /**
     * 登录
     *
     * @param loginInfo
     * @param request
     * @return
     */
    @PostMapping("/toLogin")
    @ApiOperation(value = "登录")
    public Object loginByWeixin(AdminLoginInfo loginInfo, HttpServletRequest request) {

        return loginService.toLogin(loginInfo, request);
    }


    /**
     * 退出登录
     *
     * @return
     */
    @PostMapping("/logout")
    @ApiOperation(value = "退出登录")
    @Login
    public Object logout() {
        return loginService.toLogout(getAdminId());
    }


}
